/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.unit;

import deatax.Player;
import deatax.Resource;
import deatax.ResourceAmount;
import deatax.display.Texture;
import deatax.markers.Marker;
import deatax.markers.UnitMarker;
import deatax.markers.WorkerMarker;
import java.awt.Image;
import java.util.ArrayList;

/**
 *
 * @author pson
 */
public class Unit {
    
    public static final UnitMarker MARKER_WORKER = new WorkerMarker();
    
    public static final UnitMarker MARKER_DEFAULT = MARKER_WORKER;
    
    private String name;
    private int score;
    private int movement;
    private ArrayList<String> abilities;
    private ArrayList<ResourceAmount> cost;
    private int populationCost;
    private Image portrait;
    private UnitMarker marker;

    public Unit(String name, int movement, int population_cost, int score) {
        this.name = name;
        this.movement = movement;
        this.score = score;
        this.populationCost = population_cost;
        abilities = new ArrayList<String>();
        cost = new ArrayList<ResourceAmount>();
        portrait = Texture.loadImage("unit/" + name.toLowerCase() + ".png");
        try {
            marker = new UnitMarker(null, name.toLowerCase());
            if (marker.model == null) {
                marker = null;
            }
        } catch (Exception ex) {
            marker = null;
        }
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getMovement() {
        return movement;
    }

    public void setMovement(int movement) {
        this.movement = movement;
    }

    public void addSkill(String s) {
        abilities.add(s);
    }
    
    public boolean hasSkill(String s) {
        return abilities.contains(s);
    }

    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPopulationCost() {
        return populationCost;
    }

    public void setPopulationCost(int population_cost) {
        this.populationCost = population_cost;
    }
    
    
    public void addCost(Resource r, int num) {
        this.cost.add(new ResourceAmount(r, num));
    }

    public ArrayList<ResourceAmount> getCost() {
        return cost;
    }

    public Image getPortrait() {
        return portrait;
    }
    
    public Marker getMarker(Player p, int count){
        UnitMarker m;
        if (marker != null) {
            marker.setCount(count);
            marker.setOwner(p);
            return marker;
        }
        
        m = MARKER_WORKER;
        m.setCount(count);
        m.setOwner(p);
        
        return m;
    }
}
